package com.dmatek.uwb.xml.util.iparse.bean;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.dom4j.Element;

import com.dmatek.uwb.xml.dom.bean.BasePath;
import com.dmatek.uwb.xml.util.iparse.IDomParse;
import com.dmatek.uwb.xml.util.iparse.IMapReferenceParse;
/***
 * 路径的Map解析实现类
 * @author zhangfu
 * @data 2019年6月22日 下午3:22:36
 * @Description
 */
public class PathMapParse extends BaseMapParse<BasePath, HashMap<String, BasePath>> 
	implements IMapReferenceParse {
	public static final String DOM_NAME = "paths";
	public PathMapParse(IDomParse<?> iDomParse) {
		super(iDomParse);
	}
	@Override
	public boolean isMatch(String clazzName) throws Exception {
		if(PathMapParse.DOM_NAME.equalsIgnoreCase(clazzName)) {
			return true;
		}
		return false;
	}
	@Override
	public HashMap<String, BasePath> parse(Element element,
			Map<String, Object> map) throws Exception {
		HashMap<String, BasePath> childMap = new HashMap<String, BasePath>();
		List<Element> elements = element.elements("bean");
		for (Element ele : elements) {
			// 获取Id
			String key = ele.attributeValue("id");
			Object value = getiDomParse().parse(ele, map);
			childMap.put(key, (BasePath) value);
		}
		return childMap;
	}
}
